package xyz.zhzby.cyzx.judge.util;

import lombok.NoArgsConstructor;

import java.io.IOException;

/**
 * @author zby
 * @date 2022/02/04
 * @Description Contains helper methods for loading native libraries, particularly JNI.
 * @Description 包含用于加载本机库(特别是JNI)的帮助器方法。
 */
@NoArgsConstructor
public class NativeLibraryLoader {

    /**
     * @Param [libraryName] [要加载的库的名称]
     * @Return void []
     * @Author zby
     * @Date 2022/02/04
     * @Description 如果库不能从jar文件中解压缩到临时文件中抛出IO 异常。
     * @Description 加载本机共享库。它尝试标准系统。loadLibrary方法，如果失败，则在当前类路径中查找库。它也将处理jar文件中打包的库。
     * Loads a native shared library. It tries the standard System.loadLibrary method first and if it
     * fails, it looks for the library in the current class path. It will handle libraries packed
     * within jar files, too.
     */
    public static void loadLibrary(String libraryName) throws IOException {
        try {
            System.loadLibrary(libraryName);
            System.out.println("类库加载成功.");
        } catch (UnsatisfiedLinkError e) {
            System.out.println(e.getMessage());
            System.out.println("加载native失败。");
        }
    }
}
